package com.wzdigit.wms.basic.converter.gdn;

import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.CellData;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import com.wzdigit.wms.basic.enums.GdnHeaderSaleTypeEnum;

/**
 * 发货单--销售类型
 * @author Administrator
 *
 */
public class GdnHeaderSaleTypeConverter implements Converter<Integer> {

	/**
     * java中的数据格式
     */
    @Override
    public Class<Integer> supportJavaTypeKey() {
        return Integer.class;
    }

    /**
     * Excel中的数据格式
     */
    @Override
    public CellDataTypeEnum supportExcelTypeKey() {
        return CellDataTypeEnum.STRING;
    }

    /**
     * 这里读的时候会调用
     */
    @Override
    public Integer convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {
    	GdnHeaderSaleTypeEnum data = GdnHeaderSaleTypeEnum.getEnumByName(cellData.getStringValue());
    	if(data != null) {
    		return data.getCode();
    	} else {
    		return null;
    	}
    }

	@Override
	public CellData convertToExcelData(Integer value, ExcelContentProperty contentProperty,
			GlobalConfiguration globalConfiguration) throws Exception {
		GdnHeaderSaleTypeEnum data = GdnHeaderSaleTypeEnum.getEnumByCode(value);
		if(data != null) {
    		return new CellData(data.getEnumName());
    	} else {
    		return new CellData("");
    	}
	}
}
